﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;

namespace GSync
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [MTAThread]
        static void Main()
        {

            GSyncFactory.Instance.Logger.Write("GSync started.", "info");

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            Application.Run(new Form1());

            GSyncFactory.Instance.Logger.Write("GSync closed.", "info");
            GSyncFactory.Instance.Logger.Dispose();
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            GSyncFactory.Instance.Logger.Write(
                                                string.Format( "Unhandled exception in GSync application:\r\nException object:{0}\r\n" 
                                                            , e.ExceptionObject.ToString()), 
                                                "error");
            MessageBox.Show("You should never read this message.\r\nNow I have to kill you.\r\nAre you agree?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
        }
    }
}